package com.woniuxy.microretailserver.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    /**
     * 将字符串解析为时间
     * @param str  输入的字符串
     * @param pattern  字符串的格式
     * @return
     * @throws ParseException
     */
    public static Date str2Date(String str, String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(str);
    }

    /**
     * 将时间转换为字符串
     * @param date
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static String DateToStr(Date date, String pattern) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }


}
